﻿using System;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;

public class EmailManager
{
	public EmailManager() {}
    public string SendEmail(string adressees, string messageText)
    {
        string resourseKey;
        if (adressees != "")
        {

            string[] addressees = adressees.Split(',');

            MailMessage message = new MailMessage(ConfigurationManager.AppSettings["WorkMail"], addressees[0], "PhotoRu", messageText);

            foreach (string addr in addressees)
            {
                message.To.Add(new MailAddress(addr));
            }

            SmtpClient emailClient = new SmtpClient(ConfigurationManager.AppSettings["smtp"], 25);
            emailClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["WorkMail"], "confirmit");
            try
            {
                emailClient.Send(message);
                resourseKey = "Success";
            }
            catch
            {
                resourseKey = "Error";
            }
        }
        else
        {
            resourseKey = "NoMail";
        }  
        return resourseKey; 
    }
}